<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/includes.jsp" %>
<html>
 <head>
    <title>销售出库批次管理</title>
    <!-- import css and js -->
	<%@ include file="/common/meta.jsp" %>
	<%@ include file="/common/metaInput.jsp" %>  
	<script src="${ctx}/js/ligerUI/js/plugins/ligerLayout.js" type="text/javascript"></script>
	<script type="text/javascript" src="${ctx}/js/jsp/yd/logic/ItemStateData.js"></script>
	<script src="${ctx}/js/jsp/comm.js" type="text/javascript"></script>
	<script type="text/javascript">
		var basic_Url="${ctx}/yd/logic/soware";
		var ItemStateList = ItemStateData.Rows;
// 		var item = eval("("+'${wareItemBatchDO}'+")");
		var batch = '${itemBatch}';
// 		var whcode = '${whcode}';
		var grid;
		$(function(){
			var column1 =  [
			 {display : 'ID',name : 'id',width : 1,hide : true
			}, 
			{ display: '产品id', name: 'materialsid', width: 1 , hide:true},
			{display : '<font color="gray">产品编码</font>',name : 'prodNo',width : 100
			}, {display : '<font color="gray">产品名称</font>', name : 'prodName',width : 100
			},{display : '<font color="gray">型号规格</font>',name : 'prodSpecDesc',width : 130
			},{display : '产品批次<font color="red">*</font>',name : 'prodBatch',width : 90, isSort: false
			}, 
			{ display: '等级<font color="red">*</font>', name: 'status', width: 60,
				 render: function (item){
					 var state=item.status;
           		  if(state=="1"){
           			  return "一等品";
           		  }
           		  if(state=="2"){
           			  return "次品";
           		  }
           		  if(state=="3"){
           			  return "旧件";
           		  }
				}
			},
			{display : '<font color="gray">基本单位</font>', name : 'prodBUnit',width : 80
			},{display : '<font color="gray">单位换算率</font>',name : 'prodUnitConvert',width : 80 
			},{display : '<font color="gray">单位</font>',name : 'prodUnit',width : 50
			},{display : '<font color="gray">本次可出库数量</font>',name : 'tmpCanCkQuantity',width : 100
				,render:function(item){
					item.tmpCanCkQuantity = parseFloat(item.frozenQuantity==undefined?0:item.frozenQuantity)-parseFloat(item.ckQuantity==undefined?0:item.ckQuantity)-parseFloat(item.djjdQuantity==undefined?0:item.djjdQuantity);
					return item.tmpCanCkQuantity+"";
				  }
			},{display : '本次实发数量<font color="red">*</font>',name : 'prodSfquantity',width : 90
				,editor : {type : 'float'},
				render:function(item){
				  dealProductQuantity(item);
				  return item.prodSfquantity;
			  	}
			},{display : '本次实发基本单位数量',name : 'prodBSfquantity',width : 120
			},{display : '<font color="gray">订单冻结数量</font>',name : 'frozenQuantity',width : 100
			},{display : '冻结数量基本单位数量',name : 'frozenBQuantity',width : 1,hide : true},
			{ display: '解冻基本单位数量', name: 'djjdBQuantity', width: 1 , hide:true},
            { display: '<font color="gray">本单解冻数量</font>', name: 'djjdQuantity', width: 90,
          	  render:function(item){
					if(undefined == item.djjdQuantity || null == item.djjdQuantity || isNaN(item.djjdQuantity) ){
			    		item.djjdQuantity = 0;
			    		item.djjdBQuantity = 0;
			    	}
					
				  return item.djjdQuantity+"";
			  	}
            },
			{display : '<font color="gray">本单已退数量</font>',name : 'ytQuantity',width : 80
			},{display : '已退基本单位数量',name : 'ytBQuantity',width : 1,hide : true
			},{display : '已出库基本单位数量',name : 'ckBQuantity',width : 1,hide : true
			},{display : '<font color="gray">已出库数量</font>',name : 'ckQuantity',width : 120
			}];
			
			
			var column2 =  [
			{display : 'ID',name : 'id',width : 1,hide : true
			}, 
			{ display: '产品id', name: 'materialsid', width: 1 , hide:true},
			{display : '<font color="gray">产品编码</font>',name : 'prodNo',width : 100
			}, {display : '<font color="gray">产品名称</font>', name : 'prodName',width : 100
			},{display : '<font color="gray">型号规格</font>',name : 'prodSpecDesc',width : 130
			},{display : '产品批次<font color="red">*</font>',name : 'prodBatch',width : 90, isSort: false
			}, 
			{ display: '等级<font color="red">*</font>', name: 'status', width: 60,
				 render: function (item){
					 var state=item.status;
           		  if(state=="1"){
           			  return "一等品";
           		  }
           		  if(state=="2"){
           			  return "次品";
           		  }
           		  if(state=="3"){
           			  return "旧件";
           		  }
				}
			},
			{display : '<font color="gray">基本单位</font>', name : 'prodBUnit',width : 80
			},{display : '<font color="gray">单位换算率</font>',name : 'prodUnitConvert',width : 80 
			},{display : '<font color="gray">单位</font>',name : 'prodUnit',width : 50
			},{display : '<font color="gray">本次可出库数量</font>',name : 'tmpCanCkQuantity',width : 100
			},{display : '本次实发数量<font color="red">*</font>',name : 'prodSfquantity',width : 90
			},{display : '本次实发基本单位数量',name : 'prodBSfquantity',width : 120
			},{display : '<font color="gray">订单冻结数量</font>',name : 'frozenQuantity',width : 100
			},{display : '冻结数量基本单位数量',name : 'frozenBQuantity',width : 1,hide : true},
			{ display: '<font color="gray">本单解冻数量</font>', name: 'djjdQuantity', width: 90,
	          	  render:function(item){
						if(undefined == item.djjdQuantity || null == item.djjdQuantity || isNaN(item.djjdQuantity) ){
				    		item.djjdQuantity = 0;
				    		item.djjdBQuantity = 0;
				    	}
						
					  return item.djjdQuantity+"";
				  	}
	            },
			{display : '<font color="gray">本单已退数量</font>',name : 'ytQuantity',width : 80
			},{display : '已退基本单位数量',name : 'ytBQuantity',width : 1,hide : true
			},{display : '已出库基本单位数量',name : 'ckBQuantity',width : 1,hide : true
			},{display : '<font color="gray">已出库数量</font>',name : 'ckQuantity',width : 120
			}
			                  ];
 if('${billstatus}' != "" && '${billstatus}' != "0"&& '${billstatus}' != "3"){
	 grid = $("#table1").ligerGrid({
	        columns: column2, 
	                      enabledEdit: true,
	                      usePager: true,pageSize:1000,pageSizeOptions:[1000],enabledSort:false, checkbox: true,
	                      url : basic_Url+"/pzdItemlist.do?itembatch="+encodeURIComponent(batch)+"&updstatus="+"${updstatus}",
	                      width: "100%", height:"98%"
	                  });
 }else{
	 grid = $("#table1").ligerGrid({
	        columns: column1, 
	                      enabledEdit: true,
	                      usePager: true,pageSize:1000,pageSizeOptions:[1000],enabledSort:false, checkbox: true,
	                      url : basic_Url+"/pzdItemlist.do?itembatch="+encodeURIComponent(batch)+"&updstatus="+"${updstatus}",
	                      width: "100%", height:"98%",
	                      toolbar: { items: [
	                                         { line: true },
	                                         { text: '删除', click: deleteRow, img: '${ctx}/js/ligerUI/skins/icons/delete.gif' }
	                                         ]
	                                         }
	                  });
 }
				
			$("#pageloading").hide();
		
		});
		
		function dealProductQuantity(item){
	    	if(undefined == item){
	    		return;
	    	}
	    	
	    	//计算
	    	//计算基本单位数量 parseFloat()
	    	if(!isNaN(item.prodSfquantity) && !isNaN(item.prodUnitConvert)){
	    		item.prodBSfquantity = item.prodSfquantity*item.prodUnitConvert ;
	    	}else{
	    		item.prodBSfquantity=null;//清除值
	    	}
	    	
//	     	if(!isNaN(item.prodPerCost) && !isNaN(item.prodPerCost)){
//	     		item.prodCost = item.prodPerCost*item.prodUnitConvert ;
//	     	}else{
//	     		item.prodCost=null;//清除值
//	     	}
	    	
	    }
		
// 		function getBatchkcQuantity(rowData){
// 			if(null==whcode || ""==whcode){
// 				$.dialog.alert("请先选择仓库");
// 				return ;
// 			}
// 			if (rowData.prodBatch){
// 	   		 $.ajax({
// 	     		      url: "${ctx}/yd/logic/otherOutwh/getStorageQuaitity.do",
// 	     		      global: false,
// 	     		      type: "POST",
// 	     		      dataType: "json",
// 	     		      data: ({
// 	     		    	maCode : rowData.prodNo,
// 	     				whCode : whcode,
// 	     				hubCode : "",
// 	     				status : rowData.status,
// 	     				batch : rowData.prodBatch
// 	     		      }),		     
// 	     		      success: function(msg){
// 	     		    	rowData.kyBQuantity = msg;
// 	     		    	rowData.auto = true;
// 	     	   			grid.updateCell('kyBQuantity',msg,rowData);
// 	     	   			if(!isNaN(rowData.prodUnitConvert)){
// 	 		    			rowData.kyQuantity = (rowData.kyBQuantity / rowData.prodUnitConvert);
// 	 		    			grid.updateCell('kyQuantity',rowData.kyQuantity,rowData);
// 	     	   			}
	     	   			
// 	     		      }
// 	     	   });
// 	  		}else{
// 	  			$.dialog.alert("请先选择批次");
// 	  		}
// 		}
		function dealProductQuantity(item){
	    	if(undefined == item){
	    		return;
	    	}
	    	
	    	//计算
	    	//计算基本单位数量 parseFloat()
	    	if(!isNaN(item.prodSfquantity) && !isNaN(item.prodUnitConvert)){
	    		item.prodBSfquantity = item.prodSfquantity*item.prodUnitConvert ;
	    	}else{
	    		item.prodBSfquantity=null;//清除值
	    	}
	    	
//	     	if(!isNaN(item.prodPerCost) && !isNaN(item.prodPerCost)){
//	     		item.prodCost = item.prodPerCost*item.prodUnitConvert ;
//	     	}else{
//	     		item.prodCost=null;//清除值
//	     	}
	    	
	    }
		function getSelected(){
			var rows = grid.getCheckedRows();
			 return rows;
		}
		
		function Close(){
			CloseDialog();
		}
		function deleteRow()
		{ if('${billstatus}' != "" && '${billstatus}' != "0" && '${billstatus}' != "3"){
			return false;
		}else{
			grid.deleteSelectedRow();
		}
		}
		var ba=true;
		var num = 0;
		var jnum = 0;
		function yz(){
			var data = grid.getData();
			if (data != null && data.length > 0) {
				jnum = 0;
				num = 0;
				for ( var j = 0; j < data.length; j++) {
					if (undefined == data[j].prodSfquantity
							|| isNaN(data[j].prodSfquantity)
							|| data[j].prodSfquantity <= 0) {
						$.dialog.alert("冻结出库表格，第" + (j+1) + "行的“本次实发数量”数据不合法");
						ba = false;
						return false;
					}
					
					if (parseFloat(data[j].prodSfquantity) > parseFloat(data[j].tmpCanCkQuantity)/* parseFloat(data[j].prodQuantity - data[j].ckQuantity) */) {
						$.dialog.alert("冻结出库表格，第" + (j+1) + "行的“本次实发数量”大于“本单可出库数量”");
						ba = false;
						return false;
					}
					jnum += parseFloat(data[j].prodBSfquantity);
					num += parseFloat(data[j].prodSfquantity);
	 			}
			}
				ba=true;
		}
	</script>
	
  </head>
 <body style="padding:10px">  
 <input type="hidden" id="batchItem" name="batchItem"/>
       <div id="layout1">
       <div id="layout1">
<!--           <div class="panelBar"> -->
<!-- 	            <ul class="toolBar"> -->
<!-- 		           <li><a class="add" onclick="insert()"><span>新增</span></a></li> -->
<!-- 		       		<li><a class="delete" onclick="deleteRow()"><span>删除</span></a></li> -->
<!--                </ul> -->
<!--           </div> -->
          <div id="pageHeader" class="pageHeader">
               <div class="searchBar" id="multipleSearchDialog">
	                <table class="table" width="100%" id="searchHeader" >  
                        <tbody id="newbody">
                        </tbody>
 	                </table>
<!--                     <div class="subBar"> -->
<!-- 			             <ul> -->
<!-- 				             <li><div class="buttonActive"><div class="buttonContent"><button type="submit" id="btnSearch" onclick="insert()">添加</button></div></div></li> -->
<!--  				             <li><a class="button" onclick="clearSearch()"><span>删除</span></a></li>  -->
<!-- 			             </ul> -->
<!-- 	                </div> -->
               </div>
          </div>
      </div>
      <div position="center" id="table1">
      </div>
      <div class="clear"></div>
   </div>
    </body>
</html>